package Meb;


import java.util.Hashtable;



public class ChatGroup extends AbstractChatRoom {
    private Hashtable<String, Member> members = new Hashtable<>();

    @Override
    public void register(Member member) {
        if (!members.containsKey(member.getName())) {
            members.put(member.getName(), member);
            member.setChatRoom(this); // 设置聊天室引用
        }
    }

    @Override
    public void sendText(String from, String to, String message) {
        Member member = members.get(to);
        if (member == null) {
            System.out.println("未找到成员：" + to);
            return;
        }
        String newMessage = message.replaceAll("打", "*");
        member.receiveText(from, newMessage);
    }

    @Override
    public void sendImage(String from, String to, String image) {
        Member member = members.get(to);
        if (member == null) {
            System.out.println("未找到成员：" + to);
            return;
        }

        if (image.length() > 5) {
            System.out.println("图片太大，发送失败！");
        } else {
            member.receiveImage(from, image);
        }
    }
}